String Class

A String is an intrinsic data type in REALbasic. It is a series of numeric or alphabetic characters enclosed in quotes.

Events

None

Properties

None

Methods

None

Any kind of alphabetic or numeric information can be stored as a string. "Jean Marie", "3/17/98", "45.90" are all examples of strings. When you place quotes around information in your code, you are telling REALbasic to look at the data as just a series of characters and nothing more. The maximum length of a string is limited only by available memory. The default value of a String is "".


Notes

All computers use encoding schemes to store character strings as a series of bytes. The oldest and most familiar encoding scheme is the ASCII encoding. It defines character codes only for values 0-127. These values include only the upper and lowercase English alphabet, numbers, some symbols, and invisible control codes used in early computers.

Many extensions to ASCII have been introduced which handle additional symbols, accented characters, non-Roman alphabets, and so forth. In particular, the Unicode encoding is designed to handle any language and a mixture of languages in the same string. REALbasic supports two different Unicode formats, UTF-8 and UTF-16. All of your constants, string literals, and so forth are stored internally using UTF-8 encoding.

If the strings you work with are created, saved, and read within REALbasic, you shouldn't have to worry about encoding issues because REALbasic stores the encoding it uses along with the content of the string.

Since character codes above 127 represent different characters in different encoding schemes, it is important that you understand the encoding that is used for strings that were generated outside of REALbasic. When you read in a text string using the TextInputStream class, set the Encoding property to the correct encoding or use the optional Encoding parameter of the Read, ReadLine, or ReadAll methods. You can determine the encoding of a string using the Encoding function.

If you need to save string data in a particular encoding, use the ConvertEncoding function. Specify the desired encoding using the Encodings object.

If you need to get a character that corresponds to the value of a character code, use the Chr function only if it is an ASCII code. In other cases, it is best to use the Chr method of the TextEncoding class. This enables you to specify both the encoding scheme and the desired character code.

REALbasic includes an extensive library of functions for comparing and manipulating strings, which are listed in the See Also section.

The VarType function returns 8 when passed a String.


Example

Dim s as String
s="How now brown cow"

See Also

+, <, <=, <>, =, >, >=, Asc, AscB, Chr, ChrB, ConvertEncoding, CStr, Encoding, InStr, InStrB, IsNumeric, Left, LeftB, Len, LenB, Lowercase, LTrim, Mid, MidB, NthField, Replace, ReplaceAll, Right, RightB, RTrim, Str, StrComp, Titlecase, Trim, Uppercase, Val, VarType functions; Dim, Static statements; Encodings object; TextEncoding, TextInputStream classes; Boolean, Color, Double, Integer, Single, Variant data types.